package nccu.model;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;

/**
 * This class is used to represent an exam report for a particular,
 * bank for a particular quarter.
 *
 * @author <a href="mailto:chris.oberle@gmail.com">Chris Oberle</a>
 */
@Entity
@Table(name = "exam_report")
@Searchable
@XmlRootElement
public class ExamReport extends BaseObject implements Serializable {

    private static final long serialVersionUID = 3832626162173359423L;

    private Long id;
    private String period;   // required
    private Date createDate; // auto generated
    private String filePath; // required
    private String fileName; // required

    /**
     * Default constructor - creates a new instance with no values set.
     */
    public ExamReport(){}

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @SearchableId
    @Column (name="examreport_id")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(nullable = false, length = 20, unique = false)
    @SearchableProperty
    public String getPeriod() {
        return period;
    }

    @Column(nullable = false, length = 20, unique = false)
    @SearchableProperty
    public void setPeriod(String period) {
        this.period = period;
    }

    @Column(name="create_date", nullable = false, unique = false)
    @SearchableProperty
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Column(name="file_path", nullable = false, unique = false)
    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    @Column(name="file_name", nullable = false, unique = true)
    @SearchableProperty
    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ExamReport)) return false;

        ExamReport that = (ExamReport) o;

        if (createDate != null ? !createDate.equals(that.createDate) : that.createDate != null) return false;
        if (fileName != null ? !fileName.equals(that.fileName) : that.fileName != null) return false;
        if (filePath != null ? !filePath.equals(that.filePath) : that.filePath != null) return false;
        if (id != null ? !id.equals(that.id) : that.id != null) return false;
        if (period != null ? !period.equals(that.period) : that.period != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (period != null ? period.hashCode() : 0);
        result = 31 * result + (createDate != null ? createDate.hashCode() : 0);
        result = 31 * result + (filePath != null ? filePath.hashCode() : 0);
        result = 31 * result + (fileName != null ? fileName.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "ExamReport{" +
                "id=" + id +
                ", period='" + period + '\'' +
                ", createDate=" + createDate +
                ", filePath='" + filePath + '\'' +
                ", fileName='" + fileName + '\'' +
                '}';
    }
}
